<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateShopTableOrderInvoice extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order_invoice', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('brandId')->default(0)->comment('品牌id');
            $table->unsignedInteger('shopId')->default(0)->comment('店铺 ID');
            $table->unsignedBigInteger('orderId')->comment("订单 ID");
            $table->unsignedTinyInteger('orderType')->default(1)->comment("订单类型 1: 堂食 2: 外卖");
            $table->unsignedInteger('jshj')->comment("价税合计: 单位分");
            $table->unsignedInteger('hjje')->comment("合计金额: 单位分");
            $table->unsignedInteger('hjse')->comment("合计税额: 单位分");

            $table->string('invoiceUrl', 255)->comment("二维码开票地址");
            $table->string('fpdm', 100)->comment("发票代码");
            $table->string('fphm', 100)->comment("发票号码");
            $table->string('fplxdm', 20)->comment("发票类型代码 026电子普票 028电子专票");
            $table->unsignedTinyInteger('status')->default(0)->comment("发票状态 0:提交开票 1: 有效 2:红冲 3: 已取消");
            $table->unsignedTinyInteger('supplier')->default(1)->comment("发票服务商 1:盟度");
            $table->unsignedTinyInteger('operateSource')->default(0)->comment("发票服务商 0: 无红冲/取消 1. 取消订单  2. 反结账");

            // 统一表字段
            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('updatedAt')->default(0)->comment('更新时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('更新人');

            $table->index('brandId', 'idx_brandId');
            $table->index('shopId', 'idx_shopId');
            $table->index('createdAt', 'idx_createdAt');
            $table->index('orderId', 'idx_orderId');

            $table->collation = 'utf8mb4_general_ci';
            $table->comment   = '订单开票记录';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_invoice');
    }
}
